"""
@File    :   validate.py
@Time    :   2024/03/25 12:32:11
@Author  :   Qrj
@Email   :   923207736@qq.com
@description   :   租户套餐相关的pydantic验证模型
"""

from datetime import datetime

from pydantic import BaseModel, Field, conint

from src.schemas.validate import (
    BaseSearchValidateSchemaMixin,
    BaseValidateSchemaConfigMixin,
)


class TenantPackageCreateValidateSchema(BaseModel, BaseValidateSchemaConfigMixin):
    """用于创建租户套餐的验证模型"""

    name: str = Field(default=..., min_length=1, max_length=100, description="套餐名称")
    status: bool = Field(default=True, description="状态")
    remark: str = Field(default="", min_length=1, max_length=300, description="备注")
    menu_ids: list[conint(ge=1)] = Field(default_factory=list, description="菜单权限")


class TenantPackageUpdateValidateSchema(BaseModel, BaseValidateSchemaConfigMixin):
    """用于修改租户套餐的验证模型
    不可操作系统级租户套餐(在service.py有对应的异步验证方法, 在依赖层调用)
    """

    id: int = Field(default=..., ge=1, description="主键")
    name: str = Field(default=..., min_length=1, max_length=100, description="套餐名称")
    status: bool = Field(default=True, description="状态")
    remark: str = Field(default="", min_length=1, max_length=300, description="备注")
    menu_ids: list[conint(ge=1)] = Field(default_factory=list, description="菜单权限")


class TenantPackageUpdateStatusValidateSchema(BaseModel, BaseValidateSchemaConfigMixin):
    """用于单独修改角色状态的验证模型
    不可操作系统级租户套餐(在service.py有对应的异步验证方法, 在依赖层调用)
    """

    id: int = Field(default=..., ge=1, description="主键")
    status: bool = Field(default=..., description="状态")  # (True正常 False停用)


class TenantPackageDeleteValidateSchema(BaseModel, BaseValidateSchemaConfigMixin):
    """用于删除租户套餐的验证模型"""

    ids: list[conint(ge=1)] = Field(
        default=..., min_length=1, description="需删除的主键列表"
    )


class TenantPackageListSearchValidateSchema(BaseModel, BaseSearchValidateSchemaMixin):
    """用于查询租户套餐列表的验证模型"""

    name: str | None = Field(
        default=None,
        min_length=1,
        max_length=100,
        description="套餐名称",
        json_schema_extra={"str_like_search_type": "complete"},
    )
    status: bool | None = Field(default=None, description="状态")
    remark: str | None = Field(
        default=None,
        min_length=1,
        max_length=300,
        description="备注",
        json_schema_extra={"str_like_search_type": "complete"},
    )
    create_datetime: tuple[datetime, datetime] | None = Field(
        default=None,
        description="创建时间",
        json_schema_extra={"allow_order": True},
    )
    update_datetime: tuple[datetime, datetime] | None = Field(
        default=None,
        description="修改时间",
        json_schema_extra={"allow_order": True},
    )
    creator_username: str | None = Field(
        default=None,
        min_length=1,
        max_length=20,
        description="创建者用户名",
        json_schema_extra={"str_like_search_type": "complete"},
    )
    updater_username: str | None = Field(
        default=None,
        min_length=1,
        max_length=20,
        description="修改者用户名",
        json_schema_extra={"str_like_search_type": "complete"},
    )
